package com.zntech.app.common

import android.content.Context
import android.graphics.Rect
import android.os.Bundle
import android.telephony.TelephonyManager
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.zntech.app.common.accessibility.InstantAssist
import com.zntech.app.common.instantcmd.InstantCmd

class MainActivity : AppCompatActivity() {
    companion object {
        private const val TAG = "zncommon"
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun onTestHome(view: View) {
//        InstantCmd.click(0.3f, 0.5f)
        //InstantCmd.slide(0.3f, 0.3f, 0.5f, 0.5f);
        //InstantCmd.slide(0.8f, 0.8f, 0.5f, 0.5f, 300);
        // 0.15f,0.92f
/*        Thread {
            Log.e(TAG, "double click here..")
            Thread.sleep(4000)
            InstantCmd.click(0.12f, 0.95f, 100)
            Thread.sleep(150)
            InstantCmd.click(0.12f, 0.96f, 100)

        }.start()*/

        Thread {
            Log.e(TAG, "paste here..")
            Thread.sleep(4000)
            //InstantAssist.pasteText("测试两下", "com.zntech.app.common:id/editTextTextMultiLine")
            InstantAssist.pasteText("34592", 0.5f, 0.21f)
           // InstantCmd.doPaste()
//            val shellResult = InstantAssist.execShell("ls")
//            Log.e(TAG, "shell cmd result ${shellResult.isSuccessful()}: $shellResult")
        }.start()
    }

    fun onTestEtInput(view: View) {
       // InstantCmd.doPaste()
    }

    fun onTestInstantAssist(view: View) {
        Log.e(TAG, "click here11111111..")
        Thread {
            Log.e(TAG, "click here..")
            Thread.sleep(4000)
            val values = InstantAssist.getPageText(null)// Rect(48, 746 , 694, 872)
            Log.i(TAG, "size ${values?.size}")
            if (values != null) {
                for (item in values) {
                    Log.i(TAG, "get text: ${item.text}, id: ${item.id}, range: ${item.rc}")
                }
            }
 /*          val values = InstantAssist.getPageInfoByIds(null,
               "com.tencent.mm:id/b4b",isIntersection = false)
            Log.i(TAG, "size ${values?.size}")
            if (values != null) {
                for (item in values) {
                    Log.i(TAG, "get text: ${item.text}, id: ${item.id}, range: ${item.rc}")
                }
            }*/

/*            for (i in 0 until 1000) {
                val values = InstantAssist.getPageInfoByIds(null, isIntersection = false)
                Log.i(TAG, "size ${values?.size}")
                Log.i(TAG," =======! 执行次数：$i")
                if (values != null) {
                    for (item in values) {
                        Log.i(TAG, "get text: ${item.text}, id: ${item.id}, range: ${item.rc}")
                    }
                }

                //Thread.sleep(1000)
            }*/


            //"com.tencent.wework:id/gef" com.tencent.wework:id/mj5

/*            val values = InstantAssist.findAllByText("微信")
            Log.i(TAG, "size2 ${values?.size}")
            if (values != null) {
                for (item in values){
                    Log.i(TAG, "get text3: $item")
                }
            }*/
/*            for (i in 0 until 100) {
                val values = InstantAssist.findAllByIdAndSiblingIds(
                    null,
                    "com.tencent.mm:id/hg4", "com.tencent.mm:id/kmv",
                )
                Log.i(TAG," =======!! 执行次数：$i")
                Log.i(TAG, "size ${values?.size}")
                if (values != null) {
                    for (item in values) {
                        Log.i(TAG, "get text: $item")
                    }
                }
                Thread.sleep(1000)
            }*/

        }.start()
    }

    fun onStartRecord(view: View) {
        Thread {
            Log.e(TAG, "onStartRecord..")
            Thread.sleep(2000)
            // -t 超时时间，不传默认为10s
            val shellResult = InstantAssist.execShell("shellhy ar start /sdcard/Alarms/test2.m4a -t 30")
            Log.e(TAG, "shell cmd result ${shellResult.isSuccessful()}: $shellResult")
        }.start()
    }

    fun onStopRecord(view: View) {
        Thread {
            Log.e(TAG, "onStopRecord..")
            Thread.sleep(2000)
            val shellResult = InstantAssist.execShell("shellhy ar stop")
            Log.e(TAG, "shell cmd result ${shellResult.isSuccessful()}: $shellResult")
        }.start()
    }
}